369B - Valera and Contest - CodeForces Solution


constructive algorithms implementation math *1400

Please click on ads to support us..

C++ Code:

#include <bits/stdc++.h>
#include <unordered_map>
#include<bitset>
#include <unordered_set>
#define Fast ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define sortvector(v) sort(v.begin(),v.end())
#define sortrvector(v) sort(v.rbegin(),v.rend())
#define loop(i,a,b) for(int i=a;i<b;i++)
#define vi vector<int>
typedef long long  ll;
const ll MOD = 1000000007;
using namespace std;
const int N = 100+8;
bool prime[N];
void Sieve()
{
    memset(prime, 1, sizeof(prime));
    prime[0] = prime[1] = false;
    for (int i = 2; i < N; i++) {
        if (prime[i]) {
            for (ll j = 1ll * i * i; j < N; j += i)
                prime[j] = false;
        }
    }
}
ll binaryexponentialpower(int base, int power)
{
    ll result = 1;
    while (power > 0) {
        if (power & 1)
            result *= base;
        base *= base;
        power /= 2;
    }
    return result;
}
ll __gcd(ll a, ll b) {
    while (b != 0)
    {
        ll a2 = a;
        a = b;
        b = a2 % b;
    }
    return a;
}
int GetDivisors(ll x) {
    set<int>s;
    for (ll i = 1; i * i <= x; i++) {
        if (x % i == 0)
        {
            s.insert(i);
            if (x / i != i)
            {
                s.insert(x / i);
            }
        }
    }
    return s.size();
}
//ll n;
//void solve(int length ,int level) {
//    if (level == n)
//        return;
//    for (int i = 0; i < length - 1; i++)
//        cout << ' ';
//    for (int i = 0; i < 2 * level + 1; i++)
//        cout << '*';
//    cout << '\n';
//    solve(length - 1, ++level);
//}
int main() {

    Fast
        /*freopen("input.txt", "r", stdin);
          freopen("output.txt", "w", stdout);*/
        int t = 1;

    //cin >> t;
    while (t--) {
        int mini = 1e6 + 1;
        int n, k, l, r, sall, sk;
        cin >> n >> k >> l >> r >> sall >> sk;
        vi v(n);
        int add = sk / k;
        int mod = sk % k;
        sall -= sk;
        for (int i = 0; i < k && sk>0; i++) {
            v[i] = add + (mod > 0);
            mod--;
        }
        if (k != n) {
            add = sall / (n - k);
            mod = sall % (n - k);
            for (int i = k; i < n; i++) {
                v[i] = add + (mod > 0);
                mod--;
            }
        }
        for (auto x : v)
            cout << x << ' ';
        
    }
}


Comments

Submit
0 Comments
More Questions

1002. Find Common Characters
1602A - Two Subsequences
1555A - PizzaForces
1607B - Odd Grasshopper
1084A - The Fair Nut and Elevator
1440B - Sum of Medians
1032A - Kitchen Utensils
1501B - Napoleon Cake
1584B - Coloring Rectangles
1562B - Scenes From a Memory
1521A - Nastia and Nearly Good Numbers
208. Implement Trie
1605B - Reverse Sort
1607C - Minimum Extraction
1604B - XOR Specia-LIS-t
1606B - Update Files
1598B - Groups
1602B - Divine Array
1594B - Special Numbers
1614A - Divan and a Store
2085. Count Common Words With One Occurrence
2089. Find Target Indices After Sorting Array
2090. K Radius Subarray Averages
2091. Removing Minimum and Maximum From Array
6. Zigzag Conversion
1612B - Special Permutation
1481. Least Number of Unique Integers after K Removals
1035. Uncrossed Lines
328. Odd Even Linked List
1219. Path with Maximum Gold